//
//  JCLRefreshView.swift
//  UIRefresshControlDemo
//
//  Created by DDC on 2017/9/20.
//  Copyright © 2017年 DDC. All rights reserved.
//

import UIKit

class JCLRefreshView: UIView {

    /// 设置不同的下拉状态来更新UI
    var refreshState:JCLRefreshState = .normal {
        
        didSet {
            switch refreshState {
            case .normal:
                
                tipLabel.text = "继续使劲拉"
                tipIcon.isHidden = false
                indicator.stopAnimating()
                UIView.animate(withDuration: 0.25, animations: { 
                    
                    self.tipIcon.transform = CGAffineTransform.identity
                })
            case .pulling:
                tipLabel.text = "松手刷新"
                UIView.animate(withDuration: 0.25, animations: { 
                    
                    self.tipIcon.transform = CGAffineTransform(rotationAngle:CGFloat(Double.pi - 0.001))
                })
            case .willRefresh:
                tipLabel.text = "正在刷新中..."
                tipIcon.isHidden = true
                indicator.startAnimating()
                  
     
            }
        }
    }
    /// 菊花转
    @IBOutlet weak var indicator: UIActivityIndicatorView!
    /// 提示图标
    @IBOutlet weak var tipIcon: UIImageView!
    /// 提示文字
    @IBOutlet weak var tipLabel: UILabel!
    
    /// 类方法-创建JCLRefreshView
    ///
    /// - Returns: 返回refreshView
    class func refreshView()-> JCLRefreshView {
    
        let nib = UINib(nibName: "JCLRefreshView", bundle: nil)
        return nib.instantiate(withOwner: nil, options: nil)[0] as! JCLRefreshView
    }
}
